﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using chessLogic;

namespace chessTest
{
    [TestFixture]
    class testPGNExportParser
    {
        private string pgnString = "\r\n[Event \"It\"]\r\n" +
                                "[Site \"Pistyan (Czech Republic)\"]\r\n" +
                                "[Date \"1912.??.??\"]\r\n" +
                                "[Round \"?\"]\r\n" +
                                "[White \"Lowtzky M\"]\r\n" +
                                "[Black \"Duras Oldrich\"]\r\n" +
                                "[Result \"1-0\"]\r\n" +
                                "[ECO \"A56/07\"]\r\n" +
                                "\r\n" +
                               "1.d4 Nf6 2.c4 c5 3.d5 g6 4.Nc3 d6 \r\n" +
                               "5.e4 Bg7 6.Bd3 Ng4 7.Nge2 Ne5 8.O-O O-O \r\n" +
                               "9.f4 Nxd3 10.Qxd3 f5 11.Ng3 e6 12.Be3 e5 \r\n" +
                               "13.Rae1 exf4 14.Rxf4 g5 15.Rxf5 Bxf5 16.Nxf5 Nd7 \r\n" +
                               "17.Qd2 Ne5 18.Bxg5 Qd7 19.Nb5 Nxc4 20.Qe2 Qxb5 \r\n" +
                               "21.b3 Na3 22.Qg4 Rxf5 23.exf5 Qb4 24.Re4 h5 \r\n" +
                               "25.Qe2 Bd4+ 26.Be3 Qb5 27.Qxh5 1-0\r\n";
        [Test]
        public void testTrueParseTag()
        {
            Game game = new Game();
            game.Event = "TEST";
            PGNExportParser export = new PGNExportParser();
            Assert.True(export.ParseTag(game).Contains("\r\n[Event \"TEST\"]\r\n"));
        }
        [Test]
        public void testTrueParseMove()
        {
            Game game = new Game();
            game.Moves.AddRange(new string[] { "a1", "a2", "a3" });
            game.Result = "1-0";
            PGNExportParser export = new PGNExportParser();
            string moveString = export.ParseMoves(game);
            Assert.AreEqual("\r\n1.a1 a2 2.a3 1-0\r\n", moveString);
        }
        [Test]
        public void testTrueExport()
        {
            PGNImportParser parser = new PGNImportParser("filePath");
            Game game = new Game();
            string[] temp = parser.GetPartsPGNString(pgnString);
            game.setTags(parser.GetTags(temp[0]));
            game.Moves = parser.GetMoves(temp[1]);
            List<Game> games = new List<Game>();
            games.Add(game);
            PGNExportParser export = new PGNExportParser();
            Assert.AreEqual(pgnString, export.ParseToPGNFormat(games));
        }
    }
}
